package mr

//
// RPC definitions.
//
// remember to capitalize all names.
//

import (
	"errors"
	"os"
)
import "strconv"

//
// example to show how to declare the arguments
// and reply for an RPC.
//

type ExampleArgs struct {
	X int
}

type ExampleReply struct {
	Y int
}

// Add your RPC definitions here.
type MsgType int

var (
	BadMsgType = errors.New("bad message type")
	NoMoreTask = errors.New("no more task left")
)

const (
	AskForTask      MsgType = iota // worker ask for task
	MapTaskAlloc                   // Coordinator assign map task
	ReduceTaskAlloc                // Coordinator assign reduce task
	MapSuccess                     // worker report to Coordinator finish map task successfully
	MapFailed                      // worker report to Coordinator finish map task failed
	ReduceSuccess                  // worker report to Coordinator finish reduce task successfully
	ReduceFailed                   // worker report to Coordinator finish reduce task failed
	Shutdown                       // coordinator information to worker exit(all task finished)
	Wait                           // coordinator information to worker sleep
)

type MessageSend struct {
	MsgType MsgType
	TaskId  int
}

type MessageReply struct {
	MsgType  MsgType
	TaskId   int
	NReduce  int    // map function splices number
	TaskName string // input file name
}

// Cook up a unique-ish UNIX-domain socket name
// in /var/tmp, for the coordinator.
// Can't use the current directory since
// Athena AFS doesn't support UNIX-domain sockets.
func coordinatorSock() string {
	s := "/var/tmp/5840-mr-"
	s += strconv.Itoa(os.Getuid())
	return s
}
